/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package thing;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.WindowEvent;

/**
 *
 * @author Tharen
 */
public class OptionsMenu extends Stage {

    AnchorPane pane = new AnchorPane();
    TextField worldsRoot = new TextField();
    TextField mcServerRoot = new TextField();
    Label wrLbl = new Label("Where the worlds will be stored.", worldsRoot);
    Label mcsrLbl = new Label("Where your Minecraft Server is.", mcServerRoot);
    Label lblOne = new Label();
    Label lblTwo = new Label();
    Button save = new Button("Save");
    Button cancel = new Button("Cancel");

    public OptionsMenu() {
        init();
    }

    public OptionsMenu(StageStyle arg0) {
        super(arg0);
        init();
    }

    public final void init() {
        this.setScene(new Scene(pane, 500, 300));
        this.setTitle("Options");
        pane.getChildren().add(wrLbl);
        pane.getChildren().add(mcsrLbl);
        pane.getChildren().add(lblOne);
        pane.getChildren().add(lblTwo);
        pane.getChildren().add(save);
        pane.getChildren().add(cancel);
        wrLbl.contentDisplayProperty().set(ContentDisplay.BOTTOM);
        mcsrLbl.contentDisplayProperty().set(ContentDisplay.BOTTOM);
        this.setResizable(false);
        wrLbl.relocate(10, 10);
        lblOne.relocate(200, 30);
        mcsrLbl.relocate(10, 60);
        lblTwo.relocate(200, 80);
        save.relocate(440, 270);
        cancel.relocate(10, 270);
        //Button Actions
        cancel.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent arg0) {
                hide();
            }
        });
        save.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent arg0) {
                WorldManager.setRoots(worldsRoot.getText(), mcServerRoot.getText());
            }
        });
        this.setOnShowing(new EventHandler<WindowEvent>() {

            @Override
            public void handle(WindowEvent arg0) {
                try {
                    lblOne.setText(WorldManager.getRoot().toString());
                    lblTwo.setText(WorldManager.getServerRoot().toString());
                } catch (NullPointerException ne) {
                    if (!WorldManager.getRoot().isEmpty()) {
                        lblOne.setText("e.g. C:\\Users\\Owner\\Desktop\\MyMaps");
                        AppLauncher.toUser("Check the library path statement in the options menu.");
                    }
                    if (!WorldManager.getServerRoot().isEmpty()) {
                        lblTwo.setText("e.g. C:\\Users\\Owner\\Desktop\\MCNexusDefenseServer");
                        AppLauncher.toUser("Check the server path statement in the options menu.");
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    //lblOne.setText("e.g. C:\\Users\\Owner\\Desktop\\MyMaps");
                    //lblTwo.setText("e.g. C:\\Users\\Owner\\Desktop\\MCNexusDefenseServer");
                }
            }
        });
    }
}
